package ferp.android.views.table.animation;

import android.graphics.Point;
import android.view.animation.Animation;
import ferp.android.views.CardView;
import ferp.android.views.table.TableView;
import ferp.core.game.Game;

/**
* User: olegs
* Date: 04/01/2015 22:55
*/
public class AnimationRollbackListener extends AnimationListener
{
  public AnimationRollbackListener(TableView table, CardView view, Point origin)
  {
    super(table, view);

    this.origin = origin;
  }

  @Override
  protected void onRealAnimationStart(Animation animation)
  {
    //Log.log.debug(Log.TAG, "rollback animation started");
  }

  @Override
  protected void onRealAnimationEnd(Animation animation)
  {
    Game g = table.game();
    //Log.log.debug(Log.TAG, "rollback animation ended");
    //Log.log.debug(Log.TAG, "origin: " + origin);

    view.clearAnimation();
    view.layout(origin.x, origin.y);
    // enable the card
    view.setEnabled(true);

    // enable back all candidates as user didn't make a move
    if (g.options.hand != 0)
    {
      // first redraw the cards, as their position may change if there was a layout change (ad appeared/gone)
      table.showPlayerCards(g, table.settings(), g.player.current);
      // now enable move candidates, disabling all the rest
      table.enablePlayerCards(g.player.current, g.options.hand);
      // reset controller
      table.resetController();
    }
  }

  public void onAnimationRepeat(Animation animation) {/* do nothing */}

  private Point origin;
}
